package com.xintong.visualinspection.service.impl;

import java.util.Date;
import java.util.List;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xintong.visualinspection.bean.Constant;
import com.xintong.visualinspection.bean.Task;
import com.xintong.visualinspection.bean.TaskStatus;
import com.xintong.visualinspection.dao.master.TaskDao;
import com.xintong.visualinspection.service.BaseService;
import com.xintong.visualinspection.service.TaskService;

/**
 * 文件名：UserServiceImpl
 * 版本信息：日期：2017/3/30 Copyright 江苏省交通规划设计院 Corporation 2017 版权所有.
 */
@Service
public class TaskServiceImpl extends BaseService implements TaskService {

    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TaskServiceImpl.class);
    @Autowired
    private TaskDao taskDao;

	@Override
	public List<Task> getAll() {
		// TODO Auto-generated method stub
		return taskDao.getAll();
	}


	@Override
	public Task getById(Long id) {
		// TODO Auto-generated method stub
		return taskDao.getOne(id);
	}


	@Override
	public List<Task> getTaskList(Task task) {
		// TODO Auto-generated method stub
		return taskDao.getList(task);
	}


	@Override
	public void insert(Task task) {
		// TODO Auto-generated method stub
		taskDao.insert(task);
		TaskStatus status = new TaskStatus();
		status.setTask_id(commonDao.getLastId());
		status.setUpdate_time(new Date());
		status.setUpdate_user(task.getCheckman());
		status.setUpdate_username("");
		status.setCheck_status(task.getCheck_status());
		String name = (constantDao.getByFlagAndValue(new Constant("task_status",task.getCheck_status()))).getCode_name();
		status.setCheck_status_name(name);
		taskDao.insertStatus(status);
	}


	@Override
	public void update(Task task) {
		// TODO Auto-generated method stub
		taskDao.update(task);
		TaskStatus status = new TaskStatus();
		status.setTask_id(task.getId());
		status.setUpdate_time(new Date());
		status.setUpdate_user(task.getCheckman());
		status.setUpdate_username("");
		status.setCheck_status(task.getCheck_status());
		String name = (constantDao.getByFlagAndValue(new Constant("task_status",task.getCheck_status()))).getCode_name();
		status.setCheck_status_name(name);
		taskDao.insertStatus(status);
	}


	@Override
	public void delete(Long id) {
		// TODO Auto-generated method stub
		taskDao.delete(id);
	}

}
